home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENCRYPT.SWG / 0004_ENCRYPT1.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  620b  |  25 lines

  1. Function EncryptDecrypt(S : String : K : String) : String;
  2. Var
  3.   I,Q : Integer;
  4.   O   : String[255];
  5. begin
  6.   Q := 1;
  7.   O := "";
  8.   For I := 1 to Length(S) Do
  9.     begin
  10.       O := O + Chr(Ord(S[I]) Xor Ord(K[Q]));
  11.       Inc(Q); If Q > Length(K) Then Q := 1;
  12.     end;
  13.   EncryptDecrypt := O;
  14. end;
  15.  
  16. A couple of thoughts on this.
  17.  
  18. 1. If K is short then the decryption is very easy.
  19. 2. The routine would be VERY slow as it is using String concatenation.  It
  20.    would be MUCH faster if the O := "" line was changed to O[0] := S[0] and
  21.    the O := O + ... line was replaced With -
  22.    O[I] := ...
  23.  
  24. TeeCee
  25.